<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA  -Compatible" content="ie=edge">
    <title>学习 vue 组件实验（1）：组件注册</title>
</head>
<body>
    <div id="app">
        <say-hello :who="who"></say-hello>
        <welcome-you :who="who"></welcome-you>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        // 全局组件注册
        Vue.component('say-hello', {
            template: `<h1>你好， {{ you }}！</h1>`,
            props: ['who'],
            data: function() {
                return {
                    you: this.who
                };
            }
        });

        const app = new Vue({
            el: '#app',
            // 局部组件注册
            components: {
                'welcome-you': {
                    template: `<h2>欢迎你， {{ you }}！</h2>`,
                    props: ['who'],
                    data: function() {
                        return {
                            you: this.who
                        };
                    }
                }
            },
            data: {
                who: 'vue'
            }
        });
    </script>
</body>
</html>
